<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>视频功能测试 - zut Chat</title>
    <style>
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
            background: linear-gradient(135deg, #07C160 0%, #06A84F 100%);
            min-height: 100vh;
            padding: 20px;
            margin: 0;
        }

        .container {
            max-width: 800px;
            margin: 0 auto;
            background: white;
            border-radius: 20px;
            padding: 30px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
        }

        h1 {
            text-align: center;
            color: #333;
            margin-bottom: 30px;
        }

        .test-section {
            margin-bottom: 30px;
            padding: 20px;
            border: 1px solid #e0e0e0;
            border-radius: 10px;
        }

        .test-section h3 {
            color: #07C160;
            margin-bottom: 15px;
        }

        .btn {
            background: #07C160;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 8px;
            cursor: pointer;
            font-size: 14px;
            margin-right: 10px;
            margin-bottom: 10px;
        }

        .btn:hover {
            background: #06A84F;
        }

        .result {
            margin-top: 15px;
            padding: 10px;
            border-radius: 8px;
            background: #f8f9fa;
            border-left: 3px solid #07C160;
        }

        .error {
            border-left-color: #dc3545;
            background: #f8d7da;
            color: #721c24;
        }

        .success {
            border-left-color: #28a745;
            background: #d4edda;
            color: #155724;
        }

        .video-preview {
            margin-top: 15px;
        }

        .video-preview video {
            width: 100%;
            max-width: 400px;
            border-radius: 10px;
        }

        input[type="text"] {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 8px;
            margin-bottom: 10px;
        }

        .chat-test {
            background: #f0f8ff;
            border-left-color: #2196F3;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>🎬 视频功能测试</h1>

        <div class="test-section">
            <h3>1. 获取随机视频</h3>
            <p>测试从API获取随机视频URL的功能</p>
            <button class="btn" onclick="getRandomVideo()">获取随机视频</button>
            <div id="randomVideoResult" class="result" style="display: none;"></div>
            <div id="randomVideoPreview" class="video-preview"></div>
        </div>

        <div class="test-section">
            <h3>2. 验证视频URL</h3>
            <p>测试验证视频URL是否有效的功能</p>
            <input type="text" id="videoUrlInput" placeholder="请输入视频URL">
            <button class="btn" onclick="validateVideo()">验证视频</button>
            <div id="validateResult" class="result" style="display: none;"></div>
        </div>

        <div class="test-section chat-test">
            <h3>3. 聊天室测试</h3>
            <p>在聊天室中发送以下消息来触发视频功能：</p>
            <ul>
                <li><code>小视频</code> - 请求小视频</li>
                <li><code>来个视频</code> - 请求视频</li>
                <li><code>看视频</code> - 观看视频</li>
                <li><code>视频</code> - 视频相关</li>
            </ul>
            <button class="btn" onclick="openChat()">打开聊天室</button>
        </div>

        <div class="test-section">
            <h3>4. 机器人测试</h3>
            <p>测试机器人发送视频功能</p>
            <button class="btn" onclick="testBotVideo()">测试机器人视频</button>
            <div id="botTestResult" class="result" style="display: none;"></div>
        </div>
    </div>

    <script>
        // 获取随机视频
        async function getRandomVideo() {
            const resultDiv = document.getElementById('randomVideoResult');
            const previewDiv = document.getElementById('randomVideoPreview');
            
            resultDiv.style.display = 'block';
            resultDiv.className = 'result';
            resultDiv.innerHTML = '正在获取视频...';
            previewDiv.innerHTML = '';

            try {
                const response = await fetch('/api/video/random');
                const result = await response.json();

                if (result.success) {
                    resultDiv.className = 'result success';
                    resultDiv.innerHTML = `
                        <strong>成功！</strong><br>
                        视频URL: <a href="${result.videoUrl}" target="_blank">${result.videoUrl}</a>
                    `;
                    
                    // 显示视频预览
                    previewDiv.innerHTML = `
                        <video controls preload="metadata">
                            <source src="${result.videoUrl}" type="video/mp4">
                            您的浏览器不支持视频播放
                        </video>
                    `;
                } else {
                    resultDiv.className = 'result error';
                    resultDiv.innerHTML = `<strong>失败：</strong>${result.message}`;
                }
            } catch (error) {
                resultDiv.className = 'result error';
                resultDiv.innerHTML = `<strong>错误：</strong>${error.message}`;
            }
        }

        // 验证视频URL
        async function validateVideo() {
            const videoUrl = document.getElementById('videoUrlInput').value.trim();
            const resultDiv = document.getElementById('validateResult');

            if (!videoUrl) {
                alert('请输入视频URL');
                return;
            }

            resultDiv.style.display = 'block';
            resultDiv.className = 'result';
            resultDiv.innerHTML = '正在验证...';

            try {
                const response = await fetch('/api/video/validate', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    },
                    body: `videoUrl=${encodeURIComponent(videoUrl)}`
                });
                const result = await response.json();

                if (result.success) {
                    resultDiv.className = result.valid ? 'result success' : 'result error';
                    resultDiv.innerHTML = `<strong>${result.message}</strong>`;
                } else {
                    resultDiv.className = 'result error';
                    resultDiv.innerHTML = `<strong>验证失败：</strong>${result.message}`;
                }
            } catch (error) {
                resultDiv.className = 'result error';
                resultDiv.innerHTML = `<strong>错误：</strong>${error.message}`;
            }
        }

        // 打开聊天室
        function openChat() {
            window.open('/', '_blank');
        }

        // 测试机器人视频
        async function testBotVideo() {
            const resultDiv = document.getElementById('botTestResult');
            
            resultDiv.style.display = 'block';
            resultDiv.className = 'result';
            resultDiv.innerHTML = '正在测试机器人视频功能...';

            try {
                const response = await fetch('/api/chatbot/test-video', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    },
                    body: 'botName=测试机器人'
                });
                const result = await response.json();

                if (result.success) {
                    resultDiv.className = 'result success';
                    resultDiv.innerHTML = `
                        <strong>成功！</strong><br>
                        ${result.message}<br>
                        <small>请打开聊天室查看机器人发送的视频消息</small>
                    `;
                } else {
                    resultDiv.className = 'result error';
                    resultDiv.innerHTML = `<strong>测试失败：</strong>${result.message}`;
                }
            } catch (error) {
                resultDiv.className = 'result error';
                resultDiv.innerHTML = `<strong>错误：</strong>${error.message}`;
            }
        }
    </script>
</body>
</html> 